﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using GameFramework.Taurus;
using UnityEngine;

public class TestIP : MonoBehaviour
{
    private KcpService _kcpService;
    // Use this for initialization
    void Start ()
    {
        _kcpService = new KcpService(9424, ReceiveMessage);
        _kcpService.SetTargetEndPoint("192.168.1.4", 9424);
    }

    // Update is called once per frame
    void Update ()
    {
        _kcpService?.Update();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            //_kcpService?.SendMessage(new ProtoTest(){ID=52,Commit="xxCommit",Message="ssMessage"});
            TestAsyncFunction();
        }
    }


    async void TestAsyncFunction()
    {
        object message = await _kcpService.Call(new ProtoTest() { ID = 52, Commit = "xxCommit", Message = "ssMessage" });
        ProtoTest protoTest = message as ProtoTest;
        Debug.Log($"Id:{protoTest.ID}");
    }


    private void ReceiveMessage(ushort type, object message)
    {
        ProtoTest protoTest = message as ProtoTest;
        Debug.Log($"Id:{protoTest.ID}");
    }

}
